/// @tags:
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <unordered_map>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

std::unordered_map<int, std::set<int>> xaxis, yaxis;

int main() {
  int h, w, rs, cs, n;
  cin >> h >> w >> rs >> cs;
  cin >> n;
  for (int i = 1, r, c; i <= n; ++i) {
    cin >> r >> c;
    xaxis[r].insert(c);
    yaxis[c].insert(r);
  }
  for (auto &&i : xaxis) {
    i.second.insert(0);
    i.second.insert(w + 1);
  }
  for (auto &&i : yaxis) {
    i.second.insert(0);
    i.second.insert(h + 1);
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    int l;
    char d;
    auto iter = xaxis.find(rs);
    cin >> d >> l;
    switch (d) {
      case 'L':
        iter = xaxis.find(rs);
        if (iter != xaxis.end()) {
          int wall = *--(iter->second.upper_bound(cs));
          cs = std::max(wall + 1, cs - l);
        } else {
          cs = std::max(1, cs - l);
        }
        break;

      case 'R':
        iter = xaxis.find(rs);
        if (iter != xaxis.end()) {
          int wall = *(iter->second.upper_bound(cs));
          cs = std::min(wall - 1, cs + l);
        } else {
          cs = std::min(w, cs + l);
        }
        break;

      case 'U':
        iter = yaxis.find(cs);
        if (iter != yaxis.end()) {
          int wall = *--(iter->second.upper_bound(rs));
          rs = std::max(wall + 1, rs - l);
        } else {
          rs = std::max(1, rs - l);
        }
        break;
      case 'D':
        iter = yaxis.find(cs);
        if (iter != yaxis.end()) {
          int wall = *(iter->second.upper_bound(rs));
          rs = std::min(wall - 1, rs + l);
        } else {
          rs = std::min(h, rs + l);
        }
        break;
    }
    cout << rs << ' ' << cs << '\n';
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("D - LRUD Instructions.in", "r", stdin);
  freopen("D - LRUD Instructions.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
